着色器编译目标级别
写表面着色或定期的着色器程序时,HLSL源可以被编译成不同的着色器模型”。较高的着色器编译目标允许使用更现代的GPU功能,但可能会使材质不工作的老年人或平台。
Compilation target is indicated by #pragma target name directive, for example: 编译目标的 #pragma target name 指令,例如:
#pragma target 3.5
Default compilation target
默认情况下,Unity编译着色器到几乎最低支持的目标(“2.5”);在DirectX 2着色器模型3之间。一些其他编译指令使着色器自动编译成更高的目标.:
利用几何着色器(# pragma几何)设置编译目标4。 利用细分着色器(# pragma船体或#语用域)集编译目标4.6。
Supported #pragma target names
这里是清单着色器模型支撑,大约增加的功能集(在某些情况下更高的平台/ GPU的要求):
#pragma target 2.0
在Unity支持的所有平台上工作。DX9 Shader Model 2。 算术与纹理指令数量有限;8插;没有顶点纹理采样;在片段着色器没有衍生品;没有明确的LOD纹理采样。
#pragma target 2.5 (default)
Almost the same as 3.0 target (see below), except still only has 8 interpolators, and does not have explicit LOD texture sampling. Compiles into SM3.0 on DX9, and DX11 feature level 9.3 on Windows Phone.
#pragma target 3.0
DX9 shader model 3.0: derivative instructions, texture LOD sampling, 10 interpolators, more math/texture instructions allowed. Not supported on DX11 feature level 9.x GPUs (e.g. most Windows Phone devices). Might not be fully supported by some OpenGL ES 2.0 devices, depending on driver extensions present and features used.
#pragma target 3.5 (or es3.0)
OpenGL ES 3.0 capabilities (DX10 SM4.0 on D3D platforms, just without geometry shaders). Not supported on DX9, DX11 9.x (WinPhone), OpenGL ES 2.0. Supported on DX11+, OpenGL 3.2+, OpenGL ES 3+, Metal, PS4/XB1 consoles. Native integer operations in shaders, texture arrays, etc.
#pragma target 4.0
DX11 shader model 4.0. Not supported on DX9, DX11 9.x (WinPhone), OpenGL ES 2.0/3.0/3.1, Metal. Supported on DX11+, OpenGL 3.2+, OpenGL ES 3.1+AEP, PS4/XB1 consoles. Has geometry shaders and everything that es3.0 target has.
#pragma target 4.5 (or es3.1)
OpenGL ES 3.1 capabilities (DX11 SM5.0 on D3D platforms, just without tessellation shaders). Not supported on DX9, DX11 before SM5.0, OpenGL before 4.3 (i.e. Mac), OpenGL ES 2.0/3.0. Not yet supported on Metal. Supported on DX11+ SM5.0, OpenGL 4.3+, OpenGL ES 3.1, PS4/XB1 consoles. Has compute shaders, random access texture writes, atomics etc. No geometry or tessellation shaders.
#pragma target 4.6 (or gl4.1)
OpenGL 4.1 capabilities (DX11 SM5.0 on D3D platforms, just without compute shaders). This is basically the highest OpenGL level supported by Macs. Not supported on DX9, DX11 before SM5.0, OpenGL before 4.1, OpenGL ES 2.0/3.0/3.1, Metal. Supported on DX11+ SM5.0, OpenGL 4.1+, OpenGL ES 3.1+AEP, PS4/XB1 consoles.
#pragma target 5.0
DX11 shader model 5.0. Not supported on DX9, DX11 before SM5.0, OpenGL before 4.3 (i.e. Mac), OpenGL ES 2.0/3.0/3.1, Metal. Supported on DX11+ SM5.0, OpenGL 4.3+, OpenGL ES 3.1+AEP, PS4/XB1 consoles. Note that all OpenGL-like platforms (including mobile) are treated as “capable of shader model 3.0”. WP8/WinRT platforms (DX11 feature level 9.x) are treated as only capable of shader model 2.5.